home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Disc to the Future 2
/
Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin
/
MAC
/
THINKC
/
4_0
/
STANDALO
/
BELCH!_P
/
BELCH!.C
< prev
Wrap
C/C++ Source or Header
|
1990-08-21
|
3KB
|
182 lines
/* ###################################################################
Belch! by Andrew Welch
This INIT was written completely for the fun of it. It simply randomly
plays a sound sampled from the a loud belch asychronously. I suppose
it has little redeeming social value, but I wanted to freak my brother
out a bit, and I thought others might like to play around as well.
Who says computers have to be boring?
It uses an Asynch sound library from "L Products" (on AOL) which he
adapted from Larry Rosenstein of Apple.
################################################################### */
#include <SoundMgr.h>
#define JMP 0x4EF9
#define SystemTaskTrap 0xA9B4
#define RandRange 1000
extern void AInitSnd (void);
extern OSErr ASndPlay (Handle,Boolean);
extern void AStopSnd (Boolean);
extern Boolean SndIsPlaying (void);
extern void SndTask (void);
extern pascal void CallBack (SndChannelPtr,SndCommand*);
/* ################################################################### */
/* This function returns a random number between 0 and range-1 */
int Randomize(range)
int range;
{
long rawResult;
rawResult=Random();
if (rawResult<0)
rawResult *=-1;
return((rawResult*range)/32768);
}
main()
{
asm
{
lea @savedG,A1
move.l A0, (A1)
_RecoverHandle
move.l A0,-(SP)
_DetachResource
/* Load in the sound resource */
clr.l -(SP)
move.l #'snd ',-(SP)
move.w #1,-(SP)
_GetResource
lea @sndHandle,A0
move.l (SP)+,(A0)
move.l @sndHandle,D0
tst.l D0
beq @errorOut
/* Now lock it down and detach it */
move.l @sndHandle,A0
_HNoPurge
move.l @sndHandle,A0
_HLock
move.l @sndHandle,-(SP)
_DetachResource
/* Patch SystemTask */
move #SystemTaskTrap,D0
_GetTrapAddress NEWTOOL
lea @origSysTask,A1
move #JMP,(A1)+
move.l A0,(A1)
move #SystemTaskTrap,D0
lea @patchSysTask,A0
_SetTrapAddress NEWTOOL
@errorOut
rts
/* ################################################################### */
/* THINK uses A4 to reference globals and statics */
@setupA4
lea @savedA4,A0
move.l A4,(A0)
move.l @savedG,A4
rts
/* ################################################################### */
/* THINK uses A4 to reference globals and statics */
@restoreA4
move.l @savedA4,A4
rts
/* ################################################################### */
/* Here is our patch to SystemTaskTrap */
@patchSysTask
lea @inited,A0
tst.w (A0)
bne @beenInited
move.w #1,(A0)
/* The Asynch unit hasn't been initialize yet -- do it now */
jsr @setupA4
jsr AInitSnd
jsr @restoreA4
@beenInited
/* Call this every time through SystemTask to stop the sound if it is done */
jsr @setupA4
jsr SndTask
jsr @restoreA4
jsr @setupA4
jsr SndTask
jsr @restoreA4
move.w #RandRange,-(SP)
jsr Randomize
add.l #2,SP
tst.w D0
bne @origSysTask
/* We should play the sound! */
jsr @setupA4
move.w #1,-(SP)
move.l @sndHandle,-(SP)
jsr ASndPlay
add.l #6,SP
jsr @restoreA4
@origSysTask
nop
nop
nop
/* ################################################################### */
/* Static storage */
@sndHandle dc.l 0 /* Handle to the sound we should play */
@inited dc.w 0 /* Has the sound unit been initialize? */
@savedG dc.l 0 /* PTR to our code */
@savedA4 dc.l 0 /* Saved value of A4 */
@sndFlag dc.w 0 /* Is a sound playing? */
}
}